<template>
  <el-table :data="productSkuList" style="width: 100%;">
    <el-table-column prop="code" label="sku编号">
      <template slot-scope="scope">
        <el-input v-model="scope.row.code" type="text" placeholder="请输入可选值列表，以逗号隔开" disabled/>
      </template>
    </el-table-column>
    <el-table-column prop="spData" label="商品属性">
      <template slot-scope="scope">
        <el-input v-model="scope.row.spData" type="text" placeholder="请输入可选值列表，以逗号隔开" disabled />
      </template>
    </el-table-column>
    <el-table-column prop="pic" label="图片">
      <template slot-scope="scope">
        <image-upload v-model="scope.row.pic" :limit = "1" />
      </template>
    </el-table-column>
    <el-table-column prop="price" label="价格">
      <template slot-scope="scope">
        <el-input v-model="scope.row.price" type="text" placeholder="请输入价格"/>
      </template>
    </el-table-column>
    <el-table-column prop="price" label="资源">
      <template slot-scope="scope">
        <el-select 
          v-model="scope.row.resUuid"
          filterable
          remote
          reserve-keyword
          placeholder="输入关键字查询资源"
          :remote-method="remoteMethod"
          :loading="loading">
          <el-option
            v-for="item in options"
            :key="item.uuid"
            :label="item.name"
            :value="item.uuid"
            >
          </el-option>
        </el-select>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { queryProductRes } from "@/api/supermarket/productRes";
export default {
  name: "EditProductSku",
  props: {
    // 商品规格列表
    productSkuList: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      options: [],
      name: "",
    }
  },
  created () {
    this.loadData();
  },
  methods: {
    //加载产品资源
    loadData(){
      this.loading = true;
      let queryParams = {
        name: this.name
      };
      queryProductRes(queryParams).then(response => {
        this.options = response;
        this.loading = false;
      });
    },
    //获取远程产品资源
    remoteMethod(query) {
      this.name = query;
      this.loadData();
    }
  },
}
</script>